package example;


public class Example3 {

    private static final long count = 10000001;

    public static void main(String[] args) {
        concurrency();
        serial();
    }
    private static void concurrency(){
        long start = System.currentTimeMillis();// 记录程序开始运行的时间
        Thread thread = new Thread(()->{
            int a = 0;
            for (long i = 0; i < count; i++) {
                a++;
            }
        });
        thread.start();
        int b = 0;
        for (long i = 0; i < count; i++) {
            b++;
        }
        try {
            thread.join();// 等待线程结束
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        long end = System.currentTimeMillis();// 记录结束时间
        System.out.println(end-start);
    }
    private static void serial(){
        long start = System.currentTimeMillis();
        int a = 0;
        for (long i = 0; i < count; i++) {
            a++;
        }
        int  b = 0;
        for (long i = 0; i < count; i++) {
            b++;
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
}
